<?php

namespace App\Models\Traits;

use Illuminate\Database\Eloquent\Builder;

trait HasUserGoldCash
{
    public function isGoldCashesEnough($cashes): bool
    {
        $unpaidRecordBeans = $this->myUnpaidRecordsCashPrice();
        $needBeans = big_decimal($cashes)->plus($unpaidRecordBeans);
        return $needBeans->isLessThanOrEqualTo($this->gold_cashes);
    }

    public function hadSupportedGoldCashes(): bool
    {
        return $this->goldCashes()
            ->where(function (Builder $query) {
                $query->where('remark', 'support_gold_cashes')
                    ->orWhere('remark', 'present_gold_cashes')
                    ->orWhere('remark', 'transfered_in_cashes');
            })->exists();
    }
}
